
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>部署wordpress · docker swarm实践文档</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Carey">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-emphasize/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-plus/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="build_eureka.md" />
    
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="http://carey.akhack.com" target="_blank" class="custom-link">Home</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" >
            
                <span>
            
                    
                    基础环境
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../base_book/环境介绍.html">
            
                <a href="../base_book/环境介绍.html">
            
                    
                    环境介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../base_book/环境准备.html">
            
                <a href="../base_book/环境准备.html">
            
                    
                    基础准备
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../base_book/安装docker.html">
            
                <a href="../base_book/安装docker.html">
            
                    
                    安装 docker
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../base_book/compose_file.html">
            
                <a href="../base_book/compose_file.html">
            
                    
                    compose file文档
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../base_book/registry仓库管理.html">
            
                <a href="../base_book/registry仓库管理.html">
            
                    
                    registry管理
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                    swarm 群集
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../swarm_book/创建群集.html">
            
                <a href="../swarm_book/创建群集.html">
            
                    
                    创建群集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../swarm_book/portainer.html">
            
                <a href="../swarm_book/portainer.html">
            
                    
                    swarm管理工具Portainer
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../swarm_book/群集监控.html">
            
                <a href="../swarm_book/群集监控.html">
            
                    
                    cAdvisor InfluxDB Grafana搭建监控平台
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../swarm_book/telegraf.html">
            
                <a href="../swarm_book/telegraf.html">
            
                    
                    Telegraf监控容器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../swarm_book/Chronograf.html">
            
                <a href="../swarm_book/Chronograf.html">
            
                    
                    Chronograf显示监控数据
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    swarm service
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../service_book/nginx.html">
            
                <a href="../service_book/nginx.html">
            
                    
                    部署nginx服务
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    swarm stack
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.5.1" data-path="lnmpwordpress.html">
            
                <a href="lnmpwordpress.html">
            
                    
                    部署wordpress
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="build_eureka.md">
            
                <span>
            
                    
                    部署eureka
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >部署wordpress</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div class="search-plus" id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="lnmp&#x90E8;&#x7F72;wordpress">LNMP&#x90E8;&#x7F72;wordpress</h1>
<h1 id="php&#x955C;&#x50CF;&#x5236;&#x4F5C;">php&#x955C;&#x50CF;&#x5236;&#x4F5C;</h1>
<ul>
<li>php&#x4F7F;&#x7528;<code>5.6</code>&#x7248;&#x672C;</li>
<li>php&#x4F7F;&#x7528; <code>php-fpm</code> &#x7684;&#x65B9;&#x5F0F;</li>
<li>&#x9700;&#x8981;&#x4F7F;&#x7528; <code>pdo_mysql</code> &#x6269;&#x5C55;&#xFF0C;&#x5B98;&#x65B9;&#x955C;&#x50CF;&#x65E0;&#x6CD5;&#x6EE1;&#x8DB3;&#xFF0C;&#x9700;&#x8981;&#x5B9A;&#x5236; <code>dockerfile</code></li>
</ul>
<p><strong>dockerfile:</strong></p>
<pre><code>$ cat Dockerfile
FROM php:5.6-fpm

RUN docker-php-ext-install pdo_mysql \
        &amp;&amp; docker-php-ext-install mysql \
        &amp;&amp; docker-php-ext-install mysqli \
        &amp;&amp; curl -fsSL &apos;http://pecl.php.net/get/redis-2.2.8.tgz&apos; -o redis-2.2.8.tgz \
        &amp;&amp; tar zxf redis-2.2.8.tgz \
        &amp;&amp; rm redis-2.2.8.tgz \
        &amp;&amp; ( \
                cd redis-2.2.8 \
                &amp;&amp; phpize \
                &amp;&amp; ./configure --with-php-config=/usr/local/bin/php-config \
                &amp;&amp; make &amp;&amp; make install \
        ) \
        &amp;&amp; rm -rf ../redis-2.2.8 \
        &amp;&amp; docker-php-ext-enable redis
</code></pre><p>&#x751F;&#x6210;&#x955C;&#x50CF; <code>docker build -t local/php:5.6-fpm</code></p>
<blockquote>
<p><strong>[info] &#x6CA1;&#x6709;&#x505A;&#x79C1;&#x6709;&#x4ED3;&#x5E93;&#xFF0C;stack&#x7684;&#x65F6;&#x5019;&#x9700;&#x8981;&#x6307;&#x5B9A;&#x5BB9;&#x5668;&#x8FD0;&#x884C;&#x7684;&#x8282;&#x70B9;&#x3002;&#x6B63;&#x5E38;&#x9700;&#x8981;&#x4E0A;&#x4F20;&#x5230;&#x4ED3;&#x5E93;&#x901A;&#x8FC7;pull&#x6765;&#x6267;&#x884C;</strong></p>
</blockquote>
<h1 id="&#x521B;&#x5EFA;overlay&#x7F51;&#x7EDC;">&#x521B;&#x5EFA;overlay&#x7F51;&#x7EDC;</h1>
<p>&#x6240;&#x6709;&#x7684;&#x670D;&#x52A1;&#x90FD;&#x52A0;&#x5165;&#x5230;&#x8BE5;&#x7F51;&#x7EDC;&#xFF0C;&#x5185;&#x90E8;&#x4F7F;&#x7528;&#x8BE5;&#x7F51;&#x7EDC;&#x901A;&#x4FE1;&#xFF0C;&#x53EA;&#x9700;&#x8981;&#x5C06; <code>80</code> &#x7AEF;&#x53E3;&#x66B4;&#x9732;&#x7ED9;&#x7528;&#x6237;</p>
<pre><code>docker network create --driver overlay lnmp
</code></pre><h1 id="&#x521B;&#x5EFA;yaml&#x6587;&#x4EF6;">&#x521B;&#x5EFA;YAML&#x6587;&#x4EF6;</h1>
<pre><code>$ cat lnmp.yaml 
version: &quot;3&quot;
services:
  nginx:
    image: nginx:1.12.2-alpine
    ports:
      - &quot;80:80&quot;
    volumes:
      - /data:/data/wwwroot
      - /root/lnmp/nginx.conf:/etc/nginx/nginx.conf:ro 
    deploy:
      replicas: 3
    networks:
      - backend
    depends_on:
      - php

  php:
    image: local/php:5.6-fpm
    volumes:
      - /data:/data/wwwroot
    deploy:
      replicas: 2
      placement:
        constraints:
          - node.hostname == node2
    networks:
      - backend
    depends_on:
      - redis
      - mysql

  redis:
    image: redis:3.2.11
    deploy:
      replicas: 1
    networks:
      - backend
    depends_on:
      - mysql

  mysql:
    image: mysql:5.6
    deploy:
      replicas: 1
    networks:
      - backend
    environment:
      MYSQL_ROOT_PASSWORD: mysqlpasswd
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress

networks:
  backend:
    external:
      name: lnmp
</code></pre><h1 id="&#x521B;&#x5EFA;&#x6570;&#x636E;&#x76EE;&#x5F55;">&#x521B;&#x5EFA;&#x6570;&#x636E;&#x76EE;&#x5F55;</h1>
<ul>
<li>&#x6BCF;&#x53F0;&#x8282;&#x70B9;&#x521B;&#x5EFA;<code>/data/</code>&#x76EE;&#x5F55;, &#x4F5C;&#x4E3A;web&#x7AD9;&#x70B9;&#x76EE;&#x5F55;</li>
<li>&#x521B;&#x5EFA;<code>/root/lnmp</code>&#x76EE;&#x5F55;&#xFF0C;&#x4F5C;&#x4E3A;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x5B58;&#x653E;</li>
</ul>
<blockquote>
<p><strong>[info] nginx&#x914D;&#x7F6E;&#x6587;&#x4EF6;</strong></p>
</blockquote>
<pre><code>$ cat nginx.conf
#user nginx;
worker_processes auto;

error_log /var/log/nginx/error_nginx.log crit;
pid /var/run/nginx.pid;
worker_rlimit_nofile 51200;

events {
  use epoll;
  worker_connections 51200;
  multi_accept on;
}

http {
  include mime.types;
  default_type application/octet-stream;
  server_names_hash_bucket_size 128;
  client_header_buffer_size 32k;
  large_client_header_buffers 4 32k;
  client_max_body_size 1024m;
  client_body_buffer_size 10m;
  sendfile on;
  tcp_nopush on;
  keepalive_timeout 120;
  server_tokens off;
  tcp_nodelay on;

  fastcgi_connect_timeout 300;
  fastcgi_send_timeout 300;
  fastcgi_read_timeout 300;
  fastcgi_buffer_size 64k;
  fastcgi_buffers 4 64k;
  fastcgi_busy_buffers_size 128k;
  fastcgi_temp_file_write_size 128k;
  fastcgi_intercept_errors on;

  #Gzip Compression
  gzip on;
  gzip_buffers 16 8k;
  gzip_comp_level 6;
  gzip_http_version 1.1;
  gzip_min_length 256;
  gzip_proxied any;
  gzip_vary on;
  gzip_types
    text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
    text/javascript application/javascript application/x-javascript
    text/x-json application/json application/x-web-app-manifest+json
    text/css text/plain text/x-component
    font/opentype application/x-font-ttf application/vnd.ms-fontobject
    image/x-icon;
  gzip_disable &quot;MSIE [1-6]\.(?!.*SV1)&quot;;

  #If you have a lot of static files to serve through Nginx then caching of the files&apos; metadata (not the actual files&apos; contents) can save some latency.
  open_file_cache max=1000 inactive=20s;
  open_file_cache_valid 30s;
  open_file_cache_min_uses 2;
  open_file_cache_errors on;

  log_format main &apos;$remote_addr $remote_user [$time_local] &apos;
                  &apos;&quot;$request&quot; $status $bytes_sent &apos;
                  &apos;&quot;$http_referer&quot; &quot;$http_user_agent&quot;&apos;;

######################## default ############################
  server {
  listen 80;
  server_name _;
  access_log /var/log/nginx/access_nginx.log combined;
  root /data/wwwroot;
  index index.html index.htm index.php;
  location ~ [^/]\.php(/|$) {
    fastcgi_pass php:9000;
    #fastcgi_pass unix:/dev/shm/php-cgi.sock;
    fastcgi_index index.php;
    fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    include fastcgi_params;
    }
  }

########################## vhost #############################
  include vhost/*.conf;
}
</code></pre><blockquote>
<p><strong>[info] phpinfo&#x6D4B;&#x8BD5;&#x6587;&#x4EF6;</strong></p>
</blockquote>
<pre><code>$ cat phpinfo.php 
&lt;?php
echo phpinfo();
</code></pre><blockquote>
<p><strong>[info] mysql&#x8FDE;&#x63A5;&#x6D4B;&#x8BD5;&#x6587;&#x4EF6;</strong><br>&#x4E3B;&#x673A;&#x540D;&#x548C;&#x7528;&#x6237;&#x540D;&#x7B49;&#x6839;&#x636E;<code>yaml</code>&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x586B;&#x5199;</p>
</blockquote>
<pre><code>$ cat mysql.php 
&lt;?php
$servername = &quot;mysql&quot;;
$username = &quot;wordpress&quot;;
$password = &quot;wordpress&quot;;
$dbname = &quot;wordpress&quot;;

try {
    $conn = new PDO(&quot;mysql:host=$servername;dbname=$dbname&quot;, $username, $password);
    echo &quot;&#x8FDE;&#x63A5;&#x6210;&#x529F;&quot;; 
}
catch(PDOException $e)
{
    echo $e-&gt;getMessage();
}
?&gt;
</code></pre><blockquote>
<p><strong>[info] redis&#x8FDE;&#x63A5;&#x6D4B;&#x8BD5;&#x6587;&#x4EF6;</strong></p>
</blockquote>
<pre><code>$ cat redis.php
&lt;?php

$redis = new Redis();
try {
    $redis-&gt;connect(&apos;redis&apos;, 6379);
    echo var_dump($redis-&gt;info());
}
catch(RedisException $e)
{
    echo &apos;&#x8FDE;&#x63A5;&#x5931;&#x8D25;: &apos; . $e-&gt;getMessage();
}
</code></pre><h1 id="&#x8FD0;&#x884C;lnmp&#x670D;&#x52A1;">&#x8FD0;&#x884C;lnmp&#x670D;&#x52A1;</h1>
<pre><code>docker stack deploy -c lnmp.yaml lnmp
</code></pre><p>&#x8BBF;&#x95EE;&#x670D;&#x52A1;&#xFF0C;&#x901A;&#x8FC7;&#x4EFB;&#x4F55;&#x8282;&#x70B9;&#x7684;<code>http</code>&#x90FD;&#x53EF;&#x4EE5;&#x8BBF;&#x95EE;&#x4F60;&#x7684;&#x670D;&#x52A1;.  </p>
<blockquote>
<p><strong>[info] <a href="http://{&#x8282;&#x70B9;ip}/phpinfo.php" target="_blank">http://{&#x8282;&#x70B9;ip}/phpinfo.php</a></strong> </p>
</blockquote>
<p>phpinfo&#x4FE1;&#x606F;<br><img src="https://carey-akhack-com.oss-cn-hangzhou.aliyuncs.com/book/swarm/phpinfo.png" alt=""></p>
<blockquote>
<p><strong>[info] <a href="http://{&#x8282;&#x70B9;ip}/redis.php" target="_blank">http://{&#x8282;&#x70B9;ip}/redis.php</a></strong>  </p>
</blockquote>
<p>redis info &#x4FE1;&#x606F;<br><img src="https://carey-akhack-com.oss-cn-hangzhou.aliyuncs.com/book/swarm/redis.png" alt=""></p>
<blockquote>
<p><strong>[info] <a href="http://{&#x8282;&#x70B9;ip}/mysql.php" target="_blank">http://{&#x8282;&#x70B9;ip}/mysql.php</a></strong>  </p>
</blockquote>
<p>mysql &#x8FDE;&#x63A5;&#x6210;&#x529F;<br><img src="https://carey-akhack-com.oss-cn-hangzhou.aliyuncs.com/book/swarm/mysql.png" alt=""></p>
<h1 id="&#x90E8;&#x7F72;wordpress">&#x90E8;&#x7F72;wordpress</h1>
<ul>
<li>&#x4E0B;&#x8F7D; <a href="https://cn.wordpress.org/wordpress-4.9.4-zh_CN.zip" target="_blank">wordpress-4.9.4-zh_CN.zip</a>  </li>
<li>&#x5C06;&#x5305;&#x89E3;&#x538B;&#x5E76;&#x653E;&#x7F6E;&#x5230;<code>/data</code>&#x76EE;&#x5F55;  </li>
<li>&#x8BBF;&#x95EE; <code>http://{&#x8282;&#x70B9;ip}/wordpress/index.php</code> &#x8FDB;&#x884C;&#x5B89;&#x88C5;&#x914D;&#x7F6E; 
<img src="https://carey-akhack-com.oss-cn-hangzhou.aliyuncs.com/book/swarm/wordpress_config.png" alt="">
<img src="https://carey-akhack-com.oss-cn-hangzhou.aliyuncs.com/book/swarm/wordpress_install.png" alt="">
<img src="https://carey-akhack-com.oss-cn-hangzhou.aliyuncs.com/book/swarm/wordpress.png" alt=""></li>
</ul>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                
                <a href="build_eureka.md" class="navigation navigation-next navigation-unique" aria-label="Next page: 部署eureka">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"部署wordpress","level":"1.5.1","depth":2,"next":{"title":"部署eureka","level":"1.5.2","depth":2,"path":"swarm_stack/build_eureka.md","ref":"swarm_stack/build_eureka.md","articles":[]},"previous":{"title":"swarm stack","level":"1.5","depth":1,"ref":"","articles":[{"title":"部署wordpress","level":"1.5.1","depth":2,"path":"swarm_stack/lnmpwordpress.md","ref":"swarm_stack/lnmpwordpress.md","articles":[]},{"title":"部署eureka","level":"1.5.2","depth":2,"path":"swarm_stack/build_eureka.md","ref":"swarm_stack/build_eureka.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["emphasize","alerts","code","-lunr","-search","search-plus","splitter"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"emphasize":{},"splitter":{},"code":{"copyButtons":true},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"alerts":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"search-plus":{}},"theme":"default","author":"Carey","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"docker swarm实践文档","language":"zh-hans","links":{"sidebar":{"Home":"http://carey.akhack.com"}},"gitbook":"*"},"file":{"path":"swarm_stack/lnmpwordpress.md","mtime":"2018-07-06T03:01:13.283Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-12-04T03:25:36.834Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-alerts/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-plus/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

